package com.example.apexapp;

import android.app.Application;

import android.content.SharedPreferences;
import android.util.Log;
import android.util.TypedValue;

import com.example.apexapp.View.PullRefreshViewHelper;


public class MyApp extends Application {
    private static MyApp instance = null;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    public static MyApp get() {
        return instance;

    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        PullRefreshViewHelper.get().init(14);
        PullRefreshViewHelper.get().setColors(getColors(R.color.purple_700), getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setLoadStyle(PullRefreshViewHelper.LOAD_STYLE_CIRCLE);
        PullRefreshViewHelper.get().setLoadColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setLoadText("加载中...");
        PullRefreshViewHelper.get().setEmptyImage(R.mipmap.ic_arrow_header);
        PullRefreshViewHelper.get().setEmptyColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setEmptyText("暂无数据~");
        PullRefreshViewHelper.get().setErrorImage(R.mipmap.ic_arrow_header);
        PullRefreshViewHelper.get().setErrorColor(getColors(R.color.teal_700));
        PullRefreshViewHelper.get().setErrorText("加载失败了~");
        sharedPreferences = getSharedPreferences("test",MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public SharedPreferences getSharedPreferences(){
        return sharedPreferences;
    }
    public SharedPreferences.Editor getEditor(){
        return editor;
    }
    public int getColors(int id) {

            return getResources().getColor(id);

        }

        public int getWidth(){
        return getResources().getDisplayMetrics().widthPixels;
        }
        public int getHeight(){
        return getResources().getDisplayMetrics().heightPixels;

        }
        public int dp2Sp(int dp){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,dp,getResources().getDisplayMetrics());
        }
    public int dp2Px(int dp){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,getResources().getDisplayMetrics());
    }
}

